package cc.autoapi.pucong.auto.flow.persistence.repository.api;


import cc.autoapi.pucong.auto.flow.persistence.po.api.ApiParamsPo;
import cc.autoapi.pucong.auto.flow.persistence.utils.jdbc.DatabaseUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pucong
 * @description api参数信息 service 实现类
 * @create 2024-09-24
 */
@Service
public class ApiParamsServiceImpl implements ApiParamsService {

    @Override
    public void remove(String apiId) {
        List<Object> params = new ArrayList<>();
        StringBuffer sqlBf = new StringBuffer();
        sqlBf.append("delete from auto_flow_api_params where 1=1 and api_id = ? ");
        params.add(apiId);
        DatabaseUtils.execSql(params, sqlBf.toString(), Integer.class);
    }

    @Override
    public List<ApiParamsPo> list(String apiId) {
        List<Object> params = new ArrayList<>();
        StringBuffer sqlBf = new StringBuffer();
        sqlBf.append("select * from auto_flow_api_params where 1=1 and api_id = ? order by param_code asc ");
        params.add(apiId);
        List<ApiParamsPo> apiInfoPos = DatabaseUtils.execQueryListSql(params, sqlBf.toString(), ApiParamsPo.class);
        return apiInfoPos;
    }

    @Override
    public List<ApiParamsPo> list(String apiId, Integer paramType) {
        List<Object> params = new ArrayList<>();
        StringBuffer sqlBf = new StringBuffer();
        sqlBf.append("select * from auto_flow_api_params where 1=1 and api_id = ? and param_type = ? order by param_code asc ");
        params.add(apiId);
        params.add(paramType);
        List<ApiParamsPo> apiInfoPos = DatabaseUtils.execQueryListSql(params, sqlBf.toString(), ApiParamsPo.class);
        return apiInfoPos;
    }

    @Override
    public void saveBatch(List<ApiParamsPo> list) {
        DatabaseUtils.saveBatchAuto("auto_flow_api_params", list);
    }
}
